package priv.lirenhe.javasuper.io.stream2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class InOutputStream {

	
	public static void main(String[] args) {
//		File sourceFile = new File("C:\\Users\\Administrator\\workspace\\huali\\navicat121_premium_cs_x64.exe");
//		File destFile = new File("C:\\Users\\Administrator\\workspace\\huali\\jiwang\\navicat121_premium_cs_x64.exe");
//		File sourceFile = new File("C:\\Users\\Administrator\\workspace\\huali\\20181225ר��ӿ۳���ѵ0.ppt");
//		File destFile = new File("C:\\Users\\Administrator\\workspace\\huali\\jiwang\\20181225ר��ӿ۳���ѵ0.ppt");
		File sourceFile = new File("C:\\Users\\Administrator\\workspace\\huali\\file01");
		File destFile = new File("C:\\Users\\Administrator\\workspace\\huali\\jiwang\\file01");
		
		InputStream is = null;
		OutputStream os = null;
		
		try {
			is = new FileInputStream(sourceFile);
			os = new FileOutputStream(destFile);
			
			Long startTime = System.currentTimeMillis();
			int b;
			int len = 0;
			while(true){
				b = is.read();
				System.out.print((char)b);
				os.write(b);
				len ++;
				if(len == 1024*1024){
					System.out.print(".");
					len = 0;
				}
				if(b == -1){
					break;
				}
			}
			System.out.println("��������");
			Long endTime = System.currentTimeMillis();
			System.out.println(endTime - startTime);
			
			/*
			Long startTime2 = System.currentTimeMillis();
			byte[] buffer = new byte[1024*1024];
			int length = 0;
			while((length=is.read(buffer)) != -1){
				os.write(buffer, 0, length);
				System.out.print(".");
			}
			Long endTime2 = System.currentTimeMillis();
			System.out.println("��������");
			System.out.println(endTime2 - startTime2);
			*/
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(is != null){
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
